//
//  BaseTabBarController.m
//  BulgeFramework
//
//  Created by beisheng03 on 2018/2/23.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "BaseTabBarController.h"
#import "BaseNavigationController.h"
#import "FSBaseViewController.h"
#import "LatestAnnouncedVC.h"
#import "LatestAnnLayout.h"
#import "DiscoverController.h"
#import "PersonalController.h"
#import "ShoppingCarListVC.h"
@interface BaseTabBarController ()

@end

@implementation BaseTabBarController


// 加载类进内存的时候调用,只会调用一次
+ (void)load
{
    // 获取当前类下所有的tabBarItem
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    
    //    [item setImageInsets:UIEdgeInsetsMake(5, 0, 0, 0)];
    
    //    // 设置选中标题的颜色
    //    // 创建富文本属性字典
    //    NSMutableDictionary *testAttr = [NSMutableDictionary dictionary];
    //
    //    // 描述颜色
    //    testAttr[NSForegroundColorAttributeName] = themeColor;
    //
    //    // 设置标题的富文本属性
    //    [item setTitleTextAttributes:testAttr forState:UIControlStateSelected];
    //
    //    // 问题:设置字体颜色不好使,注意:一定要先设置正常状态下字体大小
    //    // 设置正常状态下字体
    //    NSMutableDictionary *testAttrNor = [NSMutableDictionary dictionary];
    //
    //    // 描述字体
    //    testAttrNor[NSFontAttributeName] = MYFONT(13);
    //
    //    // 设置标题的富文本属性
    //    [item setTitleTextAttributes:testAttrNor forState:UIControlStateNormal];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 1 添加UITabBarController子控制器
    [self setupAllChildViewController];
    
    // 2 设置tabBar上所有按钮内容
    [self setupAllTabBarButton];
    // Do any additional setup after loading the view.
    // Do any additional setup after loading the view.
}



#pragma mark - 添加所有的子控制器
- (void)setupAllChildViewController
{
    
//    UIView *liveView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 43.6, KScreenW, 1)];
//    liveView1.backgroundColor = themeColor;
//    [nav.navigationBar addSubview:liveView1];
    
    
//    UIView *liveView2 = [[UIView alloc]initWithFrame:CGRectMake(0, 43.6, KScreenW, 1)];
//    liveView2.backgroundColor = themeColor;
//
//    UIView *liveView3 = [[UIView alloc]initWithFrame:CGRectMake(0, 43.6, KScreenW, 1)];
//    liveView3.backgroundColor = themeColor;
//
//    UIView *liveView4 = [[UIView alloc]initWithFrame:CGRectMake(0, 43.6, KScreenW, 1)];
//    liveView4.backgroundColor = themeColor;
//
    
    
    
    FSBaseViewController *homeVC = [[FSBaseViewController alloc] init];
    homeVC.navigationItem.title = @"全民疯抢";
    BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:homeVC];
//    [nav.navigationBar addSubview:liveView1];
    [self addChildViewController:nav];
    
    
    LatestAnnouncedVC *marketVc = [[LatestAnnouncedVC alloc] initWithCollectionViewLayout:[[LatestAnnLayout alloc]init]];
    marketVc.navigationItem.title = @"最新揭晓";
    BaseNavigationController *nav1 = [[BaseNavigationController alloc] initWithRootViewController:marketVc];
//    [nav1.navigationBar addSubview:liveView2];
    [self addChildViewController:nav1];
    
    DiscoverController *middleVC = [[DiscoverController alloc] initWithStyle:UITableViewStylePlain];
    middleVC.navigationItem.title = @"发现";
    BaseNavigationController *nav2 = [[BaseNavigationController alloc] initWithRootViewController:middleVC];
//    [nav2.navigationBar addSubview:liveView3];
    [self addChildViewController:nav2];
    
    
    ShoppingCarListVC *downlodVc = [[ShoppingCarListVC alloc] init];
    downlodVc.navigationItem.title = @"抢购清单";
    BaseNavigationController *nav3 = [[BaseNavigationController alloc] initWithRootViewController:downlodVc];
//    [nav3.navigationBar addSubview:liveView4];
    [self addChildViewController:nav3];
    
    
    PersonalController *meVc = [[PersonalController alloc] initWithStyle:UITableViewStyleGrouped];
    meVc.navigationItem.title = @"个人";
    BaseNavigationController *nav4 = [[BaseNavigationController alloc] initWithRootViewController:meVc];
    [self addChildViewController:nav4];
    
}




#pragma mark - 设置所有的TabBarButton
- (void)setupAllTabBarButton
{
    
    
    //精华按钮 0个子控制器
    UINavigationController *nav = self.childViewControllers[0];
    nav.tabBarItem.image = [UIImage imageNamed:@"tabbar_find_n"];
    nav.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbar_find_h"];
    nav.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabbar_sound_n"];
    nav1.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbar_sound_h"];
    nav1.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    
    UINavigationController *nav2 = self.childViewControllers[2];
    nav2.tabBarItem.image = [UIImage imageNamed:@"tabbar_find_n"];
    nav2.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbar_find_h"];
    nav2.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);

    
    UINavigationController *nav3 = self.childViewControllers[3];
    nav3.tabBarItem.image = [UIImage imageNamed:@"tabbar_download_n"];
    nav3.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbar_download_h"];
    nav3.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    
    
    UINavigationController *nav4 = self.childViewControllers[4];
    nav4.tabBarItem.image = [UIImage imageNamed:@"tabbar_me_n"];
    nav4.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbar_me_h"];
    nav4.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc{
    
    
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
